<div class="ui small publish modal">
  <i class="close icon"></i>
  <div class="header">
    Publishing: <em><%= @changeset.data.title %></em>
  </div>
  <div class="content">
    <%= form_tag "#{@action}/publish", method: "POST", id: "publish", class: "ui small form" do %>
      <div class="inline field">
        <div class="ui toggle checkbox">
          <input type="checkbox" name="news" class="hidden" value="1" checked>
          <label>Post to Changelog News <%= AdminHelpers.help_icon("Disable to publish to audio feed only.") %></label>
        </div>
      </div>

      <div class="inline field">
        <div class="ui toggle checkbox">
        <%= if Enum.any?(@changeset.data.guests) do %>
          <input type="checkbox" name="thanks" class="hidden" value="1" checked>
        <% else %>
          <input type="checkbox" class="hidden" value="0" disabled>
        <% end %>
          <label>Send "Thank You" email <%= AdminHelpers.help_icon("Each guest will receive one (requires news item).") %></label>
        </div>
      </div>
    <% end %>
    <div class="ui segment">
      <h5 class="ui header">Pre-flight Check ✅</h5>
      <table class="ui definition table">
        <thead></thead>
        <tbody>
          <tr>
            <td>Title</td>
            <td><%= @changeset.data.title %></td>
          </tr>
          <tr>
            <td>Subtitle</td>
            <td><%= @changeset.data.subtitle %></td>
          </tr>
          <tr>
            <td>Slug</td>
            <td>
              <%= @changeset.data.slug %>
          <%= if !StringKit.is_integer(@changeset.data.slug) do %>
              <div class="ui basic yellow left pointing label">not a number ⚠️</div>
          <% end %>
            </td>
          </tr>
          <tr>
            <td>Publish Time</td>
            <td>
              <%= TimeView.ts(@changeset.data.published_at) %>
            <%= if SharedHelpers.is_past?(@changeset.data.published_at) do %>
              <div class="ui basic yellow left pointing label">in the past ⚠️</div>
            <% end %>
            </td>
          </tr>
        <%= if !Enum.any?(@changeset.data.episode_hosts) do %>
          <tr>
            <td>Data Note ⚠️</td>
            <td>No hosts for this episode?</td>
          </tr>
        <% end %>
        <%= if !Enum.any?(@changeset.data.episode_guests) do %>
          <tr>
            <td>Data Note ⚠️</td>
            <td>No guests for this episode?</td>
          </tr>
        <% end %>
        <%= if !Enum.any?(@changeset.data.episode_sponsors) do %>
          <tr>
            <td>Data Note ⚠️</td>
            <td>No sponsors for this episode?</td>
          </tr>
        <% end %>
        <%= if Enum.any?(@changeset.data.episode_sponsors, fn(s) -> is_nil(s.starts_at) || is_nil(s.ends_at) end) do %>
          <tr>
            <td>Data Note ⚠️</td>
            <td>Some sponsors are missing start/end timestamp info</td>
          </tr>
        <% end %>
        <%= if !Enum.any?(@changeset.data.episode_topics) do %>
          <tr>
            <td>Data Note ⚠️</td>
            <td>No topics for this episode?</td>
          </tr>
        <% end %>
        <%= if Changelog.StringKit.blank?(@changeset.data.notes) do %>
          <tr>
            <td>Data Note ⚠️</td>
            <td>No notes for this episode?</td>
          </tr>
        <% end %>
        <%= if !Enum.any?(@changeset.data.audio_chapters) do %>
          <tr>
            <td>Chapters Note ⚠️</td>
            <td>No chapters for this episode?</td>
          </tr>
        <% end %>
        <%= if !@changeset.data.plusplus_file do %>
          <tr>
            <td>Audio Note ⚠️</td>
            <td>No ++ file for this episode?</td>
          </tr>
        <% end %>
      <%= if @changeset.data.plusplus_file do %>
        <%= if !Enum.any?(@changeset.data.plusplus_chapters) do %>
          <tr>
            <td>Chapters Note ⚠️</td>
            <td>No ++ chapters for this episode?</td>
          </tr>
        <% end %>
        <%= if @changeset.data.audio_duration <= @changeset.data.plusplus_duration do %>
          <tr>
            <td>Audio Note ⚠️</td>
            <td>The ++ file is longer (or same length as) the public file</td>
          </tr>
        <% end %>
      <% end %>
        </tbody>
      </table>
    </div>
  </div>
  <div class="actions">
    <input type="submit" form="publish" name="publish" class="ui primary basic button" value="Publish">
    <div class="ui basic cancel button">Cancel</div>
  </div>
</div>
